var path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin') //生成主页插件

module.exports = {
  // 1入口
  entry: {
    main: './main.js'
  },
  //2 出口
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'mybundle.js'
  },
  //3模式
  mode: 'production', // development开发       production：生产模式,
  // 4.loader
  module: {
    rules: [
      {
        //npm install -D babel-loader @babel/core @babel/preset-env
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader']
      },
      {
        //解析图片的 url-loader
        test: /\.(png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192
            }
          }
        ]
      },
      {
        //file-loader 文件管理的loader
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'file-loader',
            options: {}
          }
        ]
      }
    ]
  },
  //5插件
  plugins: [
    new HtmlWebpackPlugin({
      filename: './index.html',
      title: '微信'
    })
  ]
}
